package com.atguigu.behavior.observer;

import java.util.ArrayList;
import java.util.List;

public class WeatherFirstData implements Subject{
    private Double temperature;
    private Double pressure;
    private Double humidty;
    private final List<Observer> observerList;

    public WeatherFirstData() {
        observerList=new ArrayList<>();
    }

    public void setData(Double temperature,Double pressure,Double humidty){
        this.temperature=temperature;
        this.pressure=pressure;
        this.humidty=humidty;
        notifyObserver();
    }

    @Override
    public void registerObserver(Observer observer) {
        this.observerList.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        this.observerList.remove(observer);
    }

    @Override
    public void notifyObserver() {
        for (Observer observer : observerList) {
            observer.update(this.temperature,this.pressure,this.humidty);
            observer.display();
        }
    }
}
